/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package BL;

import BO.Concepto;
import DA.BDConnection;
import DA.DAConceptos;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author Daniel.Cerdas
 */
public class BLConcepto {

   
    private Concepto NuevoConcepto;
    private BDConnection DBConexion= new BDConnection();

    public BLConcepto() {
    }
    
    public void AgregarConcepto(JTextField ID, JTextField Descripcion, JTextField Monto) throws SQLException{
        NuevoConcepto = new Concepto(ID.getText(),Descripcion.getText(), Double.parseDouble(Monto.getText()));
        DBConexion.AgregarConcepto(NuevoConcepto);
      
    }
    public void EditarConcepto(JTextField ID, JTextField Descripcion, JTextField Monto) throws SQLException{
       // DBConexion.BuscarConcepto(Integer.parseInt(ID.getText()));
        DBConexion.ModificarConcepto(ID.getText(), Descripcion.getText(), Double.parseDouble(Monto.getText()));
       
    }
    public void DeshabilitarConcepto(){
    }
     public static DefaultTableModel CargarTablaConceptos(DefaultTableModel model) {
       BDConnection DBConexiones =  new BDConnection();
       ArrayList Lista =  new ArrayList();
       DAConceptos ConexionBDConceptos = new DAConceptos();
        try {
            Lista=ConexionBDConceptos.obtenerConceptos();
        } catch (SQLException ex) {
            Logger.getLogger(BLViaticoPorDia.class.getName()).log(Level.SEVERE, null, ex);
        }
        ListIterator<Concepto> ListaIn = Lista.listIterator();
        for(int i=(model.getRowCount()-1);i>=0;i--){
        model.removeRow(i);
        }
        while(ListaIn.hasNext()){
            Concepto conceptos = new Concepto();
            conceptos= ListaIn.next();
            model.addRow(new Object[]{conceptos.getDescripcionConcepto(),conceptos.getIdConcepto(),conceptos.getMonto(),"Editar"});  
        } 
       return model;
    }
}
